﻿using System;
using System.Collections.Generic;
using System.Text;

namespace unitlib
{
    /// <summary>
    /// 毫米的三次方,常用于截面系数
    /// </summary>
    public readonly struct Unit_mm3 : IUnit
    {
        public double Value { get; }
        public string Unit => "mm^3";

        public string LatexUnit => "\\mathrm{mm^3}";

        public Unit_mm3(double value) { Value = value; }
        public Unit_mm3 Round(int digits) => new Unit_mm3(Math.Round(Value, digits));
        //数值与字符串转换
        public override string ToString() => Value.ToString();
        public static explicit operator Unit_mm3(double value) => new Unit_mm3(value);
        public static explicit operator double(Unit_mm3 value) => value.Value;
        public static implicit operator Unit_mm3(string value) => new Unit_mm3(value.Parse());
        //比较运算
        public static bool operator ==(Unit_mm3 left, Unit_mm3 right) => left.Equals(right);
        public static bool operator !=(Unit_mm3 left, Unit_mm3 right) => !left.Equals(right);
        public override bool Equals(object obj) => obj is Unit_mm3 other && other.Value == Value;
        public override int GetHashCode()
        {
            unchecked
            {
                return GetType().GetHashCode() * 31 + Value.GetHashCode();
            }
        }
        //常规运算
        public static Unit_mm3 operator +(Unit_mm3 left, Unit_mm3 right) => new Unit_mm3(left.Value + right.Value);
        public static Unit_mm3 operator -(Unit_mm3 left, Unit_mm3 right) => new Unit_mm3(left.Value - right.Value);
        public static Unit_mm3 operator *(Unit_mm3 left, UnitValue right) => new Unit_mm3(left.Value * right.Value);
        public static Unit_mm3 operator *(UnitValue left, Unit_mm3 right) => new Unit_mm3(left.Value * right.Value);
        public static Unit_mm3 operator /(Unit_mm3 left, UnitValue right) => new Unit_mm3(left.Value / right.Value);
        public static UnitValue operator /(Unit_mm3 left, Unit_mm3 right) => new UnitValue(left.Value / right.Value);
        //新增运算  
        public static Unit_mm2 operator /(Unit_mm3 left, Unit_mm right) => new Unit_mm2(left.Value / right.Value);
    }
}
